import boardTpl from './tpl/board.tpl';
import itemTpl from './tpl/item.tpl';
import './index.scss';
import tools from '../../utils/tools';
import { NoDataTip } from '../no_data_tip';

class ShowBoard {
  constructor (el, phoneDatas) {
    this.name = 'showBoard';
    this.$el = el;
    this.phoneDatas = phoneDatas;
  }
  init () {
    this.render()
  }
  render () {
    this.$el.append(tools.tplReplace(boardTpl(), {
      list: this.renderList(this.phoneDatas) || new NoDataTip().tpl('未搜索到相关数据')
    }))
  }
  renderList (datas) {
    let list = '';
    datas.forEach((item, idx) => {
      list += tools.tplReplace(itemTpl(), {
        id: item.id,
        isFirst: idx % 5 === 0 ? 'first' : '',
        pic: $.parseJSON(item.pics)[0][0][0],
        phone_name: item.phone_name,
        slogan: item.slogan.substr(0, 10),
        default_price: item.default_price
      })
    })
    return list;
  }
}
export { ShowBoard }